var http = require('http');
var querystring = require('querystring');

var allmess={
    CompanyId:'0010',
    Source:'wyc1',
    IPCType:'baseInfoCompany',
    baseInfoCompany:
        [

            {"id":5,"CompanyId":"0313","CompanyName":"淄博饭店集团淄博群方出租车有限公司", "Identifier":"1236548214","Address":"370301","ContactAddress":"张店区中心路177号","EconomicType":"141","RegCapital":"100","LegalName":"法人1","LegalID":"372501","LegalPhone":"0533-2180888","LegalPhoto":"","State":0,"Flag":1,"UpdateTime":"20180502092830" },
            {"id":4,"CompanyId":"0702","CompanyName":"桓台爱使汽车服务有限公司", "Identifier":"123456","Address":"123456","ContactAddress":"contactaddress4","EconomicType":"141","RegCapital":"104","LegalName":"法人2","LegalID":"372504","LegalPhone":"0533-2312627","LegalPhoto":"","State":0,"Flag":1,"UpdateTime":"20180502092830" },
            {"id":3,"CompanyId":"0801","CompanyName":"高青县恒通汽车运输有限责任公司", "Identifier":"12345","Address":"370301","ContactAddress":"contactaddress2","EconomicType":"141","RegCapital":"103","LegalName":"法人3","LegalID":"372503","LegalPhone":"0533-2312628","LegalPhoto":"","State":0,"Flag":1,"UpdateTime":"20180502092830" },
            {"id":2,"CompanyId":"0901","CompanyName":"沂源大众交通运输有限责任公司", "Identifier":"131306321244","Address":"370323","ContactAddress":"沂源县交通局南邻","EconomicType":"141","RegCapital":"100","LegalName":"法人4","LegalID":"372502","LegalPhone":"0533-3433456","LegalPhoto":"","State":0,"Flag":1,"UpdateTime":"20180502092830" }
            ]

};

/*
for(var j=0;j<3000;j++)
{
    var item={ "CompanyId":"0010","VehicleNo":"6002"+j,"VehicleRegionCode":"370031","PositionTime":"1524321478","Longitude":"118.234",        "Latitude":"36.234","Speed":"29","Direction":"81","Elevation":"31","Mileage":"","Encrypt":"","WarnStatus":"","VehStatus":"","BizStatus":"","OrderId":"003"};
    allmess["positionVehicle"].push(item);
}
*/

var contents = JSON.stringify(allmess);

var buf = new Buffer(contents,'utf8');

var options = {
    host:'127.0.0.1',
    // path:'/api.php/Node/index', port:8001,
    path:'/api.php/baseinfo/company',  port:8001,
    method:'POST',
    headers:{
        'Content-Type':'application/json',
        'Content-Length':buf.length
    }
}

var req = http.request(options, function(res){
    res.setEncoding('utf8');
    res.on('data',function(data){
        console.log("data:",data);   //一段html代码
    });
});

req.on("timeout", function() {
    console.log("timeout received");
    if (req.res) {
        req.res.emit("abort");
    }

    req.abort();
});


//console.log(contents.toString('binary'));
//var buf = new Buffer(contents.toString('binary'),'binary');
req.write(buf);
req.end;